package com.sky.es.api;

import com.sky.es.entity.ProductDoc;
import com.sky.es.service.ProductBoolQueryEsService;
import com.sky.es.service.ProductEsService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yangsk
 */
@RestController
@RequestMapping("/es/querys")
public class DSLQueryAPI {
  @Autowired
  private ProductEsService productEsService;
  @Autowired
  private ProductBoolQueryEsService boolService;

  @ApiOperation(value = "es的tem查询", notes = "es的tem查询")
  @ApiImplicitParam(name="type",value="商品类型",required = true,dataType ="String",paramType = "query")
  @GetMapping("/term")
  public List<ProductDoc> getTermQuery(@RequestParam("type")String type){
        return productEsService.getTermQueryByType(type);
  }

  @ApiOperation(value = "es的tems查询", notes = "es的tems查询")
  @ApiImplicitParams({
    @ApiImplicitParam(name="onwPrice",value="商品价格",required = true,dataType ="Long",paramType = "query"),
    @ApiImplicitParam(name="twoPrice",value="商品价格",required = true,dataType ="Long",paramType = "query")
  })
  @GetMapping("/terms")
  public List<ProductDoc> getTermsQuery(@RequestParam("onwPrice")Long onwPrice, @RequestParam("twoPrice")Long twoPrice){
    return productEsService.getTermsQueryByPrice(onwPrice,twoPrice);
  }

  @ApiOperation(value = "es的ragne查询", notes = "es的range查询")
  @ApiImplicitParams({
          @ApiImplicitParam(name="onwPrice",value="商品价格",required = true,dataType ="Long",paramType = "query"),
          @ApiImplicitParam(name="twoPrice",value="商品价格",required = true,dataType ="Long",paramType = "query")
  })
  @GetMapping("/range")
  public List<ProductDoc> getRangeQuery(@RequestParam("onwPrice")Long onwPrice, @RequestParam("twoPrice")Long twoPrice){
    return productEsService.getRnageQueryByPrice(onwPrice,twoPrice);
  }

  @ApiOperation(value = "es的全文搜索match查询", notes = "es的全文搜索match查询")
  @ApiImplicitParam(name="name",value="商品名称",required = true,dataType ="String",paramType = "query")
  @GetMapping("/match")
  public List<ProductDoc> getMatchQuery(@RequestParam("name")String name){
    return productEsService.getMatchQueryByName(name);
  }

  @ApiOperation(value = "es的全文搜索多字段match查询", notes = "es的全文搜索多字段match查询")
  @ApiImplicitParam(name="condition",value="多字段条件",required = true,dataType ="String",paramType = "query")
  @GetMapping("/multi_match")
  public List<ProductDoc> getMultiMatchQuery(@RequestParam("condition")String condition){
    return productEsService.getMultiMatchQueryByConditioin(condition);
  }

  @ApiOperation(value = "es的全文搜索match_all查询", notes = "es的全文搜索match_all查询")
  @GetMapping("/match_all")
  public List<ProductDoc> getMatchAllQuery(){
    return productEsService.getMatchAllQuery();
  }

  @ApiOperation(value = "es的全文搜索短语match_phrase查询", notes = "es的全文搜索短语match_phrase查询")
  @ApiImplicitParam(name="condition",value="短语条件",required = true,dataType ="String",paramType = "query")
  @GetMapping("/match_phrase")
  public List<ProductDoc> getMatchPhrase(@RequestParam("condition")String condition){
    return productEsService.getMatchPhrase(condition);
  }

  @ApiOperation(value = "es的bool查询一", notes = "es的bool查询一")
  @ApiImplicitParam(name="price",value="价格",required = true,dataType ="Long",paramType = "query")
  @GetMapping("/bool/must_one")
  public List<ProductDoc> getMustByPrice(@RequestParam("price")Long price){
    return boolService.getMustByPrice(price);
  }

  @ApiOperation(value = "es的bool查询二", notes = "es的bool查询二")
  @GetMapping("/bool/two")
  public List<ProductDoc> getBollQueryTwo(){
    return boolService.getBollQueryTwo();
  }

  @ApiOperation(value = "es的bool查询三", notes = "es的bool查询三")
  @GetMapping("/bool/threee")
  public List<ProductDoc> getBollQueryThree(){
    return boolService.getBollQueryThree();
  }
  @ApiOperation(value = "es的bool查询三之混合嵌套查询", notes = "es的bool查询三之混合嵌套查询")
  @GetMapping("/bool/four")
  public List<ProductDoc> getBollQueryFour(){
    return boolService.getBollQueryFour();
  }
}
